<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="addDepository" type="primary" style="width: 100%" icon="plus">新增</a-button>
      <!--<a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <!--<div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>-->

      <div class="list">
        <van-list
          v-model="loading"
          :finished="finished"
          offset="100"
          finished-text="没有更多了"
          @load="onLoadList"
          :immediate-check="false"
        >
          <div
            class="customer-list"
            v-for="(item,i) in dataSource"
            :key="i"
          >
            <div>
              <div class="name">仓库名称：{{ item.depositoryName || '无' }}</div>
              <div class="contact">
                <span>仓库种类数量：{{ item.depositoryKindNum || 0 }}</span>
              </div>
              <div class="contact">
                <span>仓库材料数量：{{ item.depositoryMaterialNum || 0 }}</span>
              </div>
              <div class="contact">
                <span>仓库状态：
                  <a-tag color="green" v-if="item.depositoryStatus === 1">启用</a-tag>
                  <a-tag color="orange" v-if="item.depositoryStatus === 2">停用</a-tag>
                </span>
                <span style="float: right">
                  <a @click="editDepository(item)">编辑</a>
                  <a-divider type="vertical" />
                  <a-popconfirm title="确定删除吗?" @confirm="() => deleteDepository(item.id)">
                    <a>删除</a>
                  </a-popconfirm>
                </span>
              </div>
              <div class="contact">
                <span>预警数量：{{item.inventoryWarningNum || 0}}</span>
              </div>
              <div class="contact">
                <span>预警通知用户：{{item.informantName || '无'}}</span>
              </div>
            </div>
          </div>
        </van-list>
      </div>

      <!--<a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :customRow="setRow"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onSelectAll:onSelectAll,
          onSelect:onSelect,
          onChange: onSelectChange,
          type:'checkbox'
        }"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="editDepository(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => deleteDepository(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>-->
    </div>

    <depository-modal ref="depositoryModal" @ok="modalFormOk"></depository-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import depositoryModal from "./modules/depositoryModal";
  import { getAction, deleteAction } from "../../../../api/manage";
  export default {
    name: 'depositoryList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      depositoryModal
    },
    data () {
      return {
        description: '仓库管理表管理页面',
        /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
        queryParam: {},
        /* 数据源 */
        dataSource:[],
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        /* 排序参数 */
        isorter:{
          column: 'createTime',
          order: 'desc',
        },
        /* 筛选参数 */
        filters: {},
        /* table加载状态 */
        loading:false,
        /* 查询折叠 */
        toggleSearchStatus:false,
        /* 高级查询条件生效状态 */
        superQueryFlag:false,
        /* 高级查询条件 */
        superQueryParams: '',
        /** 高级查询拼接方式 */
        superQueryMatchType: 'and',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'仓库名称',
            align:"center",
            dataIndex: 'depositoryName'
          },
          {
            title:'仓库种类数量',
            align:"center",
            dataIndex: 'depositoryKindNum'
          },
          {
            title:'仓库材料数量',
            align:"center",
            dataIndex: 'depositoryMaterialNum'
          },
          {
            title:'仓库状态',
            align:"center",
            dataIndex: 'depositoryStatus',
            customRender:function (text) {
              return text == 1 ? <a-tag color="green">启用</a-tag> : <a-tag color="orange">停用</a-tag>
            }
          },
          {
            title:'预警数量',
            align:"center",
            dataIndex: 'inventoryWarningNum',
          },
          {
            title:'预警通知用户',
            align:"center",
            dataIndex: 'informantName',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/ghSupplychainDepository/list",
          delete: "/ghSupplychainDepository/delete",
          deleteBatch: "/ghSupplychainDepository/deleteBatch",
          exportXlsUrl: "/ghSupplychainDepository/exportXls",
          importExcelUrl: "/ghSupplychainDepository/importExcel",

        },
        dictOptions:{},
        selectedRowKeys: [],
        selectedRows: [],
        finished: false,
      }
    },
    created() {

    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      modalFormOk(){
        this.loadData(1);
      },
      addDepository(){
        this.$refs.depositoryModal.title = "添加";
        this.$refs.depositoryModal.add();
      },
      editDepository(record){
        this.$refs.depositoryModal.title = "修改";
        this.$refs.depositoryModal.edit(record);
      },
      deleteDepository(id){
        var that = this;
        deleteAction(that.url.delete, {id: id }).then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.loadData(1);
          } else {
            that.$message.warning(res.message)
          }
        })
      },
      onLoadList(e){
        this.ipagination.current++
        this.loadData(this.ipagination.current)
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
          this.dataSource = []
          this.finished = false;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = [...this.dataSource, ...res.result.records]
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
          if(res.result.records.length<10){
            this.finished = true;
          }
        }).finally(() => {
          this.loading = false
        })
      },
      onSelectAll(selected, selectedRows, changeRows) {
        if(selected) {
          let rows = [...selectedRows]
          this.selectedRows = this.selectedRows.concat(rows)
        } else {
          changeRows.forEach(item => {
            const delIndex = this.selectedRows.findIndex((val) => {
              return val.id === item.id
            })
            this.selectedRows.splice(delIndex, 1)
          })
        }
      },
      onSelect(record, selected) {
        if(selected) {
          this.selectedRows.push(record);
        } else {
          const delIndex = this.selectedRows.findIndex((val) => {
            return val.id === record.id
          })
          this.selectedRows.splice(delIndex,1)
        }
      },
      onSelectChange(selectedRowKeys) {
        this.selectedRowKeys = selectedRowKeys;
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';

  .remarkTxt{
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /deep/ .van-dropdown-menu__bar{
    height: 30px;
    box-shadow: none;
    border: 1px solid lightgrey;
    border-radius: 5px;
  }

  .list{
    overflow-y: scroll;
    height:calc(100vh - 155px);
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .customer-list {
    align-items: center;
    border-top: 1px solid #d9d9d9;
    /*height: 120px;*/
  }
  .name{
    margin-top: 10px;
    margin-bottom: 5px;
    font-size: 13px;
    color: #161616;
    line-height: normal;
  }
  .contact{
    font-size: 12px;
    color: #a39f9f;
    margin-bottom: 5px;
  }
</style>